package rui.example.spring.boot.mybatis.moreDatasource.configuraion;


import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import rui.example.spring.boot.mybatis.moreDatasource.dao.slave.SlaveTablesMapper;

import javax.sql.DataSource;

@Configuration
@AutoConfigureAfter({MyBatisConfigurationSupport.class})
@MapperScan(basePackageClasses = {SlaveTablesMapper.class},sqlSessionFactoryRef = "slaveSqlSessionFactory")
public class SlaveMybatisConfiguration {
    @Bean("slaveSqlSessionFactory")
    @Qualifier("slaveSqlSessionFactory")
    public SqlSessionFactory slaveSqlSessionFactory(MybatisAutoConfiguration mybatisAutoConfiguration
            , @Qualifier("slaveDataSource")DataSource slaveDataSource) throws Exception {
        return mybatisAutoConfiguration.sqlSessionFactory(slaveDataSource);
    }
}
